//
//  CellForActivityVC.m
//  echo
//
//  Created by dllo on 16/2/24.
//  Copyright © 2016年 Danny. All rights reserved.
//

#define WIDTH [UIScreen mainScreen].bounds.size.width / 414
#define HEIGHT [UIScreen mainScreen].bounds.size.height / 736

#import "CellForActivityVC.h"
#import "ModelForActivityCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <DKNightVersion.h>

@interface CellForActivityVC ()
@property (nonatomic, retain)UIView *viewOfBack;
@property (nonatomic, retain)UIView *viewOfWhite;
@property (nonatomic, retain)UILabel *labelForTop;
@property (nonatomic, retain)UIImageView *imageViewForPic;
@property (nonatomic, retain)UILabel *labelForMid;
@property (nonatomic, retain)UILabel *labelForJoin;
@property (nonatomic, retain)UILabel *labelForBottom;
@end
@implementation CellForActivityVC

- (void)dealloc{
    [_viewOfBack release];
    [_viewOfWhite release];
    [_labelForTop release];
    [_imageViewForPic release];
    [_labelForMid release];
    [_labelForJoin release];
    [_labelForBottom release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.viewOfBack = [[UIView alloc]init];
        [self.contentView addSubview:self.viewOfBack];
        self.viewOfBack.backgroundColor = [UIColor colorWithRed:218 / 255.f green:219 / 255.f blue:216 / 255.f alpha:1];
        [_viewOfBack release];
        
        self.viewOfWhite = [[UIView alloc]init];
        [self.viewOfBack addSubview:self.viewOfWhite];
        self.viewOfWhite.backgroundColor = [UIColor whiteColor];
        [_viewOfWhite release];
        
        self.labelForTop = [[UILabel alloc]init];
        [self.viewOfBack addSubview:self.labelForTop];
        [_labelForTop release];
        
        self.imageViewForPic = [[UIImageView alloc]init];
        [self.viewOfBack addSubview:self.imageViewForPic];
        [_imageViewForPic release];
        
        self.labelForMid = [[UILabel alloc]init];
        [self.viewOfBack addSubview:self.labelForMid];
        [_labelForMid release];
        
        self.labelForJoin = [[UILabel alloc]init];
        [self.viewOfBack addSubview:self.labelForJoin];
        [_labelForJoin release];
        
        self.labelForBottom = [[UILabel alloc]init];
        [self.viewOfBack addSubview:self.labelForBottom];
        [_labelForBottom release];
        
        [self handleNightModel];
    }
    
    return self;
    
    
    
}

- (void)handleNightModel{
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"夜间模式"]) {
        
        [DKNightVersionManager nightFalling];
        
    } else {
        
        [DKNightVersionManager dawnComing];
    }
    self.viewOfBack.dk_backgroundColorPicker = DKColorWithColors([UIColor colorWithRed:218 / 255.f green:219 / 255.f blue:216 / 255.f alpha:1], [UIColor colorWithRed:17 / 256.f green:27 / 256.f blue:47 / 256.f alpha:1]);
    self.viewOfWhite.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor colorWithRed:17 / 256.f green:27 / 256.f blue:47 / 256.f alpha:1]);
    self.labelForTop.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    self.labelForMid.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    self.labelForJoin.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    self.labelForBottom.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);

}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    self.viewOfBack.frame = self.contentView.frame;

    
    self.viewOfWhite.frame = CGRectMake(8 * WIDTH, 12 * HEIGHT, self.contentView.frame.size.width - 16 * WIDTH, self.contentView.frame.size.height - 12 * HEIGHT);

    
    self.labelForTop.frame = CGRectMake(16 * WIDTH, 12 * HEIGHT, self.contentView.frame.size.width / 3, 25 * HEIGHT);
    
    self.imageViewForPic.frame = CGRectMake(0, 12 * HEIGHT + 25 * HEIGHT, self.contentView.frame.size.width, 168 * HEIGHT);
    
    self.labelForMid.frame = CGRectMake(16 * WIDTH, 12 * HEIGHT + 25 * HEIGHT + 168 * HEIGHT, self.contentView.frame.size.width - 32 * WIDTH, 35 * HEIGHT);
    self.labelForMid.font = [UIFont fontWithName:@"Arial-BoldMT" size:18.0];

    
    self.labelForJoin.frame = CGRectMake(16 * WIDTH, 12 * HEIGHT + 25 * HEIGHT + 168 * HEIGHT + 35 * HEIGHT, self.contentView.frame.size.width / 2, 25 * HEIGHT);

    self.labelForBottom.frame = CGRectMake(16 * WIDTH, 12 * HEIGHT + 25 * HEIGHT + 168 * HEIGHT + 35 * HEIGHT + 25 * HEIGHT, self.contentView.frame.size.width - 32 * WIDTH, 53 * HEIGHT);
}

- (void)passDataForActivityCell:(ModelForActivityCell *)model{
    if (model.expire == 0) {
        self.labelForTop.textColor = [UIColor greenColor];
        self.labelForTop.text = @"     正在进行";
        self.labelForTop.font = [UIFont fontWithName:@"Arial" size:16.0];
    }else if (model.expire == 1){
        self.labelForTop.textColor = [UIColor greenColor];
        self.labelForTop.text = @"     往期活动";
        self.labelForTop.font = [UIFont fontWithName:@"Arial" size:16.0];
    }

    [self.imageViewForPic sd_setImageWithURL:[NSURL URLWithString:model.preview_pic]];
    self.labelForMid.text = model.title;
    
    NSString *str1 = [NSString stringWithFormat:@"%ld", (long)model.user_count];
    NSString *str2 = [str1 stringByAppendingString:@" 人参与"];
    NSRange range1 = [str2 rangeOfString:str1];
    NSMutableAttributedString *attribue1 = [[NSMutableAttributedString alloc]initWithString:str2];
    [attribue1 addAttributes:@{NSForegroundColorAttributeName: [UIColor greenColor]} range:range1];
    [self.labelForJoin setText:str1];
    [self.labelForJoin setAttributedText:attribue1];
    [attribue1 release];
    
    self.labelForBottom.text = model.preview_text;
    self.labelForBottom.font = [UIFont fontWithName:@"Arial" size:16.0];
    self.labelForBottom.numberOfLines = 0;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
